<!--------------------------------------------------------------------------->  
<!--                           INTRODUCTION                                

 The Code Project article submission template (HTML version)

Using this template will help us post your article sooner. To use, just 
follow the 3 easy steps below:
 
     1. Fill in the article description details
     2. Add links to your images and downloads
     3. Include the main article text

That's all there is to it! All formatting will be done by our submission
scripts and style sheets. 

-->  
<!--------------------------------------------------------------------------->  
<!--                        IGNORE THIS SECTION                            -->
<html>
<head>
<title>The Code Project</title>
<Style>
BODY, P, TD { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt }
H2,H3,H4,H5 { color: #ff9900; font-weight: bold; }
H2 { font-size: 13pt; }
H3 { font-size: 12pt; }
H4 { font-size: 10pt; color: black; }
PRE { BACKGROUND-COLOR: #FBEDBB; FONT-FAMILY: "Courier New", Courier, mono; WHITE-SPACE: pre; }
CODE { COLOR: #990000; FONT-FAMILY: "Courier New", Courier, mono; }
</style>
<link rel="stylesheet" type=text/css href="http://www.codeproject.com/styles/global.css">
</head>
<body bgcolor="#FFFFFF" color=#000000>
<!--------------------------------------------------------------------------->  


<!-------------------------------     STEP 1      --------------------------->
<!--  Fill in the details (CodeProject will reformat this section for you) -->

<pre>
Title:       Time Zone Handling Library
Author:      Artyom Pasyukov 
Email:       wtom@narod.ru
Member ID:   187438
Language:    C++
Platform:    Windows
Technology:  Win32
Level:       Beginner
Description: An article on something-or-other
Section      Time Zones
SubSection   
License:     CPOL
</pre>

<!-------------------------------     STEP 2      --------------------------->
<!--  Include download and sample image information.                       --> 

<ul class=download>
<li><a href="Article_demo.zip">Download demo project - XXX Kb </a></li>
<li><a href="Article_src.zip">Download source - XXX Kb</a></li>
</ul>

<!-------------------------------     STEP 3      --------------------------->

<!--  Add the article text. Please use simple formatting (<h2>, <p> etc)   --> 

<h2>Introduction</h2>

<p>TimeZone project is a static library with helps to work with any timezone taking into account daylight savings history.

<h2>Background</h2>

<p>About time zone database read
<p><a href=http://www.codeproject.com/KB/dotnet/WorldClock.aspx>http://www.codeproject.com/KB/dotnet/WorldClock.aspx</a>
<p>About doomsday rule read</p>
<p><a href=http://www.codeproject.com/KB/datetime/doomsdaydate.aspx>http://www.codeproject.com/KB/datetime/doomsdaydate.aspx</a></p>
<p>About DynamicDST (DYNAMIC_TIME_ZONE_INFORMATION) read
<p><a href=http://msdn.microsoft.com/en-us/library/ms724253(VS.85).aspx>http://msdn.microsoft.com/en-us/library/ms724253(VS.85).aspx</a>
<p>Before using this library read
<p><a href=http://blogs.technet.com/dst2007/archive/2007/03/11/time-zones-not-updating-on-windows-2003-windows-xp-or-windows-2000.aspx>http://blogs.technet.com/dst2007/archive/2007/03/11/time-zones-not-updating-on-windows-2003-windows-xp-or-windows-2000.aspx</a>
and
<p><a href=http://support.microsoft.com/kb/951072/>http://support.microsoft.com/kb/951072/</a>

<h2>Using the Code</h2>

<pre>
/*	
 *	The bias, standardBias and daylightBias fields follow the rule: UTC = local + bias + daylight bias if summer time.
 *	Day value in the standard date and daylight date values is an N-th sunday from 1-th of month. Not the real day of month!
 *	local_time stands for local for that time zone time.
 */

namespace TimeZone
{
    class Time : public SYSTEMTIME
    {
        //  ...
        
    public:
        Time(void);
        Time(const SYSTEMTIME& time);
        explicit Time(int utc);
        ~Time(void);

        operator SYSTEMTIME&        (void)       { return *this; }
        operator const SYSTEMTIME&  (void) const { return *this; }

        bool                        isValid(void) const;
        void                        print(void) const;
        int                         compare(const SYSTEMTIME& _right) const;
        bool                        operator < (const SYSTEMTIME& _right) const;
        bool                        operator <=(const SYSTEMTIME& _right) const;
        bool                        operator ==(const SYSTEMTIME& _right) const;
        int                         utc(int bias_sec) const; // if date is not valid, result is unspecified.
    };

    class TimeZone
    {
        //	...
    
    public:
        TimeZone(void);
        ~TimeZone(void);

        void                        clear(void);
        void                        print(const _tstring& prefix) const;

        int                         biasMinutes(const Time& local_time, Time* started_at = 0, Time* expired_at = 0) const;
        int                         biasSeconds(int utc, int* started_at_utc = 0, int* expired_at_utc = 0) const;
        void                        toUniversalTime(Time& local_time, Time* universal) const;
        bool                        isStandardTime(const Time& local_time) const;

        static	void                enumZones(void);
        static	bool                getZone(int index, TimeZone* dest);
    };
    
    class Bias
    {
        //	...

    public:
        Bias(int tz_index);
        ~Bias();

        int                         biasSeconds(const Time& local_time);
        int                         biasSeconds(int utc);
    };

    class Utc
    {

        //	...

    public:
        Utc(int source_tz_index);
        ~Utc(void);

        static int                  fromSecondsFromMidnight(int seconds_from_midnight);
    };

} // namespace TimeZone
</pre>

<p>Information about timezones and dynamic daylight savings schedule is loaded from HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones.</p>
<p>class Bias is mainly for caching last used time zone information. It uses already loaded time zone while </p>
<p>Provided by unique timezone, Utc class can convert seconds elapsed from midnight in given time zone to UTC.</p>

<h2>History</h2>

<!-------------------------------    That's it!   --------------------------->
</body>

</html>
